package com.lej.core.common

import androidx.annotation.IntDef
import com.lej.core.utils.KV

const val RESULT_SELECT_SCHOOL = 125//选择学校返回
const val RESULT_UPLOAD_PIC = 136//选择上传图片视频返回
const val RESULT_SELECT_RANK = 137//选择榜单返回
const val RESULT_SELECT_LOCATION = 138//选择位置返回
const val SCHOOL_CODE = "schoolCode"
const val SCHOOL_NAME = "schoolName"

const val IS_ORDER_DETAIL = "IS_ORDER_DETAIL" //是否是进入求购订单详情 true 是
const val ORDER_DETAIL_ID = "ORDER_DETAIL_ID" //订单详情id
const val PAY_DETAIL_ID = "PAY_DETAIL_ID" //传递nftId到购买页
const val IS_ORDER_PAY_DETAIL = "IS_ORDER_PAY_DETAIL" //是否是进入求购页 true 是

const val TOKEN = "token"
const val OS = "os"
const val VERSION = "version"
const val AND_ID = "androidid"
const val OAID = "oaid"
const val IMEI = "imei"
const val LOCATION = "location"

@Deprecated("使用[PCacheInfo.userId]替代")
const val USER_ID = "userId"//用户id
const val USER_NAME = "userName"//用户名

@Deprecated("使用[PCacheInfo.accId]替代")
const val ACC_ID = "accId"//云信id

@Deprecated("使用[PCacheInfo.AccToken]替代")
const val ACC_TOKEN = "AccToken"//云信token
const val PHONE = "phone"//登录的手机号

const val HTTP_UUID = "uuid"//后台记录id


const val RESULT_DATA = "RESULT_DATA"

/**mmkv的属性**/
object PCacheInfo {
    var agreePermission by KV(0)//用户隐私协议是否同意,状态

    var firstInstall by KV(true) //是否第一次安装
    var firstShowEditName by KV(true) //是否第一次展示更新用户名弹窗

    var pushClose by KV(false)//推送开关

    var nick by KV("")//用户名
    var bindPhone by KV(false)
    var userId by KV(-1)//用户id
    var accId by KV("")//云信id
    var token by KV("")//Peng 鉴权用的token
    var headImg by KV("") //用户头像

    var isAuth by KV(false) //是否实名认证

    //im相关
    var imId by KV("")//腾讯云id
    var imToken by KV("")//腾讯云token

    var accToken by KV("")//云信token
    var sex by KV(SEX_UNKNOWN)//性别
    var cate by KV(0)//用户角色

    ///推送设备id
    var clientId by KV("")
    var versionCode by KV(0L)
    var oaid by KV("")

    /**uuid用于记录设备标识*/
    var uuid by KV("")

    /**上次判断剪贴板时间*/
    var lastCheckClipboardTime by KV(0L)

    /**上次剪贴码内容(如果获取不到时间,以此判断)*/
    var lastCheckClipboardCode by KV("")

    /**人脸检测状态*/
    var faceCheckStatus by KV(CHECK_UNKNOWN)
    fun cleanUserInfo() {
        accId = ""
        accToken = ""
        userId = -1
        token = ""
        nick = ""
        bindPhone = false
        sex = SEX_UNKNOWN
        imId = ""
        imToken = ""
    }

    fun userToken() = if (userIsLogin()) "Bearer $token" else ""
}

const val USER_NORMAL = 0  //普通用户
const val USER_CREATOR = 1  //创作者
const val USER_SEX = "userSex"//用户性别
const val USER_CITY = "userCity"//用户城市
const val USER_AVATAR = "userAvatar"//用户头像

const val ERROR_CODE = "errorCode"//错误码,全局类型错误,需要统一处理的
const val WEB_URL = "webUrl"
const val WEB_PARAMS = "WEB_PARAMS"
const val WEB_SHOW_TITLE = "WEB_SHOW_TITLE"
const val TITLE = "title"

const val FRAGMENT_WEB_TAG = "FRAGMENT_WEB_TAG"

const val ORIENTATION_PORTRAIT = "ORIENTATION_PORTRAIT"//是否需要竖屏


const val ToMyMsgLogout = "ToMyMsgLogout" //跳转mymsglogout
const val MyToSet = "MyToSet" //跳转设置页
const val ToLogin = "ToLogin" //跳转登页

const val UnityRoomType = "UnityRoomType" //进入空间的类型（领取，浏览...）
const val UnityRoomId = "UnityRoomId" //空间id
const val UnityRoomNftId = "UnityRoomNftId" //空间nft id
const val UnityTargetUid = "UnityTargetUid" //目标uid

const val UnityRoomShopType = "UnityRoomShopType" //shopType
const val UnityRoomShopId = "UnityRoomShopId" //shopId
const val UnityRoomGoodsId = "UnityRoomGoodsId" //goodsId
const val UnityRoomIsAvatar = "UnityRoomIsAvatar" //isAvatar

const val QID = "QID"
const val TASK_ID = "TASK_ID"
const val TASK_COVER = "TASK_COVER"
const val CONTENT = "content"

const val UPLOAD_INFO = "uploadInfo"


const val WALLET_INFO = "WALLET_INFO"


//用户使用协议以及隐私授权状态(为防止后续隐私授权内容更新,所以使用int型数据而不是boolean型)
const val NOT_PERMISSION = 0//没有进行授权
const val HAS_PERMISSION_1 = 1//授予了权限1


//聊天室
const val ROOM_ID = "roomId"
const val ROOM_INFO = "roomInfo"
const val PHOTO_ID = "photoId"
const val ROOM_INDEX = "roomIndex"

//社区
const val COMMUNITY_NEW = 1//最新
const val COMMUNITY_LOCATION = 2//最近
const val COMMUNITY_HOT = 3//最热

//榜单卡片类型
//0:周边,1:聚合页面,2.分类排行榜,3.h5页面
const val CARD_TYPE_LOCATION = 0
const val CARD_TYPE_ALL = 1
const val CARD_TYPE_CLASS = 2
const val CARD_TYPE_H5 = 5
const val CARD_TYPE_PERSON = 6
const val CARD_TYPE_WEB = 7

//是否本人类型
const val PIC_UNKNOWN = 0//未知
const val PIC_UN_SELF = 1//非本人
const val PIC_SELF = 2//本人

//1表示聊天室,0表示单聊
const val PRIVATE_CHAT = 0//单聊
const val ROOM_CHAT = 1//聊天室

const val LIST_P2P = 0//普通消息
const val LIST_SYSTEM = 1//系统

//是否P图
const val PIC_PS = 1//p图
const val PIC_UN_PS = 2//未p图

//个人中心
const val SEX_UNKNOWN = 0//未知
const val SEX_BOY = 1//男
const val SEX_GIRL = 2//女
const val SEX_SECRET = 3//保密

//停留的页面
const val PICK_PAGE = 1//pick页面
const val PICK_RESULT_PAGE = 2//结果页

//传递认证的类型
const val CHECK_TYPE = "checkType"
const val SCHOOL_TYPE = 1//学校认证
const val FACE_TYPE = 2//真人认证

//审核相关
const val CHECK_STATUS = "checkStatus"
const val CHECK_UNKNOWN = 0//未知|未上传|待完善
const val CHECK_UN_PASS = 1//拒绝
const val CHECK_PASS = 2//通过
const val CHECK_ING = 3//待审核

@IntDef(value = [CHECK_UNKNOWN, CHECK_UN_PASS, CHECK_PASS, CHECK_ING])
annotation class CheckStatus

//在校状态
const val AT_SCHOOL = 1//在校
const val UN_AT_SCHOOL = 2//毕业

//comm
const val TYPE_PIC = 0//图片

const val TYPE_VIDEO = 1//视频


//支付类型
const val PAY_BY_WX = 1//微信支付
const val PAY_BY_AIPAY = 2//支付宝支付




//会员体系
const val VIP0 = 0//无会员
const val VIP1 = 301//会员1 (中级星探)
const val VIP2 = 302//会员2 (高级星探)
const val VIP3 = 303//会员3 (神秘星探)


///任务会员等级
const val TASK_VIP0 = 0//无会员
const val TASK_VIP1 = 100//会员1 (初级)
const val TASK_VIP2 = 200//会员2 (中级)
const val TASK_VIP3 = 300//会员3 (高级)

@IntDef(value = [VIP0, VIP1, VIP2, VIP3])
annotation class VIPLevel

//是否显示年龄//1展示年龄 0不展示年龄
const val SHOW_AGE = 1
const val UN_SHOW_AGE = 0

//注册
const val LOGIN_STATUS = "loginStatus"

const val STEP_LOGIN = -1//跳转登录页面
const val STEP_LOGIN_SUCCESS = 3//已经到过首页登陆成功

//打卡类型
const val PUNCH_TYPE = "punchType"
const val PUNCH_TYPE_RANK = 0//排行榜
const val PUNCH_TYPE_AR = 1//AR
const val PUNCH_TYPE_COMMUNITY = 2//社区

//页面
const val PAGE_RANK = 0//排行榜
const val PAGE_COMMUNITY = 1
const val PAGE_MINE = 2
const val PAGE_MESSAGE = 3

//battle状态
const val BATTLE_NO = -1//没有battle信息
const val BATTLE_ING = 0//未结束
const val BATTLE_LEFT_WIN = 1//左胜
const val BATTLE_RIGHT_WIN = 2//右胜
const val BATTLE_DOGFALL = 3//平局

//榜单解锁状态
const val RANK_UNLOCK = 1 //已解锁
const val RANK_LOCK = 0//未解锁

@IntDef(value = [RANK_UNLOCK, RANK_LOCK])
annotation class RankLockStatus

//battle是否开始
const val BATTLE_P2P_STATUS_UN_START = 0//0未battle
const val BATTLE_P2P_STATUS_START = 1// 1battle中


//二选一选中状态
const val UN_SELECT = 0//未选中
const val SELECT_LEFT = 1//选中左边
const val SELECT_RIGHT = 2//选中右边
const val Lock_LEFT_ALL = 3//左边like全选
const val SELECT_RIGHT_ALL = 4//右边like全选


//聊天类型
const val CHAT_TYPE_ROOM = 1 //群聊
const val CHAT_TYPE_NORMAL = 2 //私聊

const val FACE_RESULT = "FaceResult"//人脸专家接口返回数据
const val HEAD_PATH = "headPath"//设置头像的原始路径


//设备类型
val DEVICE_HUAWEI = "huawei"
val DEVICE_XIAOMI = "xiaomi"
val DEVICE_VIVO = "vivo"
val DEVICE_OPPO = "oppo"

///页面传递参数
object Params {
    ///用户id
    const val UID = "uid"

    ///性别
    const val GENDER = "GENDER"

    ///带不带返回按键
    const val WITH_BACK = "WITH_BACK"

    //注册
    const val IS_REGISTER = "IS_REGISTER"

    ///头像上传界面只上传头像
    const val HEAD_JUST_AVATAR = "HEAD_JUST_AVATAR"

    ///用户信息[MyUserInfo]
    const val USER_INFO = "USER_INFO"

    ///榜单卡片信息[RankCard]
    const val CARD_INFO = "CARD_INFO"

    ///聊天室(私聊)信息   [P2PChatInfo] 主要需要下面两个参数[uid]用户id [accid]聊天id
    const val CHAT_ROOM_INFO = "CHAT_ROOM_INFO"

    ///聊天室(私聊)当前index
    const val CHAT_ROOM_INDEX = "CHAT_ROOM_INDEX"

    ///当前index
    const val INDEX = "INDEX"

    //nftid
    const val NFT_ID = "NFT_ID"
    const val PACKAGE_ID = "PACKAGE_ID"
    const val NFT_TYPE = "NFT_TYPE"
    //求购
    const val NFT_TYPE_WANT = 2
    //购买
    const val NFT_TYPE_BUY = 1

    /**任务等级*/
    const val TASK_LEVEL = "TASK_LEVEL"

    const val VIP_LEVEL = "VIP_LEVEL"

    ///vip特权名
    const val VIP_PRIVILEGE_NAME = "VIP_PRIVILEGE_NAME"

    const val BATTLE_ID = "BATTLE_ID"

    ///聊天室(私聊)是否展示排名
    const val CHAT_ROOM_SHOW_INDEX = "CHAT_ROOM_SHOW_INDEX"

    ///私聊 总是允许（不做收费限制）
    const val CHAT_ALWAYS_ALLOW = "CHAT_ALWAYS_ALLOW"

    //是否需要分享
    const val USER_HAS_SHARE = "USER_HAS_SHARE"

    ///私聊 显示送红包弹窗
    const val CHAT_SHOW_RED_PACKET_DIALOG = "CHAT_SHOW_RED_PACKET_DIALOG"

    ///封面链接
    const val COVER_URL = "COVER_URL"

    ///用户排行榜信息[RANKING]
    const val RANK_INFO = "RANK_INFO"

    ///用户排行榜id
    const val RANK_TAG_ID = "RANK_TAG_ID"

    ///位置点
    const val POINT = "POINT"

    ///商品信息
    const val GOODS_INFO = "GOOLDS_INFO"

    ///描述信息
    const val DESC = "DESC"

    ///pick结果json
    const val PICK_RESULT_JSON = "PICK_RESULT_JSON"
}

/** 加上code 才会走onActivityResult, Arouter 调用的时候注意*/
object PRequestCode {
    const val UPLOAD_HEAD = 0x100
    const val UPLOAD_STUDENT_CARD = 0x101
    const val USER_INFO_EDIT = 0x102
    const val QA_EDIT = 0x103
}

/**
 * 根据类型获取性别字段
 */
fun getSex(sexType: Int) = when (sexType) {
    SEX_UNKNOWN -> ""
    SEX_BOY -> "男"
    SEX_GIRL -> "女"
    SEX_SECRET -> "保密"
    else -> ""
}

fun getCheckStatus(status: Int) = when (status) {
    CHECK_UNKNOWN -> "未认证"
    CHECK_UN_PASS -> "被拒绝"
    CHECK_PASS -> "已认证"
    CHECK_ING -> "审核中"
    else -> "未知"
}

fun hasPermission() = PCacheInfo.agreePermission > 0

fun userIsLogin() = PCacheInfo.token.isNotEmpty() && PCacheInfo.nick.isNotEmpty()



